import execjs
import requests

def get_v():
    jsFile = open('问财hexin-v和ta_random_userid参数.js', 'r', encoding='utf-8').read()
    jsx = execjs.compile(jsFile).call('O')
    return jsx

def get_ta_random_userid():
    jsFile = open('问财hexin-v和ta_random_userid参数.js', 'r', encoding='utf-8').read()
    jsx = execjs.compile(jsFile).call('getRandomStr')
    return jsx

v = get_v()
headers = {
    "Connection": "keep-alive",
    "Pragma": "no-cache",
    "Cache-Control": "no-cache",
    "Accept": "application/json, text/plain, */*",
    "hexin-v": v,
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
    "Content-Type": "application/json",
    "Origin": "http://www.iwencai.com",
    "Referer": "http://www.iwencai.com/unifiedwap/result?w=20231103^%^E6^%^B6^%^A8^%^E5^%^81^%^9C^&querytype=stock^&addSign=1699011282597",
    "Accept-Language": "zh-CN,zh;q=0.9"
}
cookies = {
    "ta_random_userid": get_ta_random_userid(),
    "v": v
}
url = "http://www.iwencai.com/customized/chart/get-robot-data"

data =  {
        "add_info": '{"urp":{"scene":1,"company":1,"business":1},"contentType":"json","searchInfo":true}',
        "block_list": "",
        'log_info': '{"input_type":"typewrite"}',
        'page': '1',
        'perpage': '50',
        'query_area': "",
        'question': "20231103涨停",
        'rsh': 'null',
        'secondary_intent': "stock",
        'source': "Ths_iwencai_Xuangu",
        'version': "2.0",
    }
response = requests.post(url, headers=headers, cookies=cookies, json=data,verify=False)

print(response.text)